import tkinter as tk

# 冒泡排序核心算法
def bubble_sort(arr):
    n = len(arr)
    for i in range(n):
        for j in range(0, n-i-1):
            if arr[j] > arr[j+1]:
                arr[j], arr[j+1] = arr[j+1], arr[j]
    return arr

def bubble():
    # 返回字符串并分隔成数组列表
    input_str = entry.get()
    input_list = [int(x) for x in input_str.split()]
    sorted_list = bubble_sort(input_list)
    result_label.config(text="排序结果: " + ", ".join(map(str, sorted_list)))

# 创建主窗口
root = tk.Tk()
root.title("冒泡排序")

# 创建输入框
entry = tk.Entry(root)
entry.pack(pady=10)
entry.insert(0,'1 3 2 5 61 17 9')

# 创建排序按钮
sort_button = tk.Button(root, text="冒泡排序", command=bubble)
sort_button.pack()

# 创建结果标签
result_label = tk.Label(root, text="排序结果: ")
result_label.pack(pady=10)

# 运行主循环
root.mainloop()